package com.isale.web.sys.controller;

import com.isale.common.json.AjaxUtil;
import com.isale.model.db.IsaleGoods;
import com.isale.service.IsaleGoodsService;
import net.sf.json.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by baijs on 2016/11/24.
 */
@Controller
@RequestMapping("/sys/goods/")
public class GoodsController {

    private static final Log logger = LogFactory.getLog(GoodsController.class);

    @Autowired
    private IsaleGoodsService isaleGoodsService;

    @RequestMapping("index.html")
    public String index() {
        return "sys/goods/list";
    }

    @RequestMapping("add.html")
    public String add() {
        return "sys/goods/add";
    }

    @RequestMapping("save.ajax")
    @ResponseBody
    public JSONObject save(IsaleGoods isaleGoods) {
        System.out.println(isaleGoods.toString());
        isaleGoodsService.save(isaleGoods);
        return AjaxUtil.success();
    }

    @RequestMapping("delete.ajax")
    @ResponseBody
    public JSONObject delete(Long id) {
        isaleGoodsService.deleteById(id);
        return AjaxUtil.success();
    }

    @RequestMapping("/cat/add.html")
    public String catAdd() {
        return "sys/goods_cat/add";
    }

    @RequestMapping("/cat/index.html")
    public String catList() {
        return "sys/goods_cat/list";
    }

    @RequestMapping("/cat/edit.html")
    public String catEdit() {
        return "sys/goods_cat/edit";
    }

}
